package com.mtw.bbs.bbsUser.controller.provider;



import com.mtw.bbs.bbsUser.pojo.entity.ResourceAPI;
import com.mtw.bbs.bbsUser.service.MenuService;
import com.mtw.bbs.bbsUser.service.ResourceAPIService;
import com.mtw.bbs.bbsUser.service.RoleService;
import com.mtw.bbs.common.core.vo.Result;
import com.mtw.bbs.userAdmin.pojo.vo.MenuVo;
import com.mtw.bbs.userAdmin.pojo.vo.RoleVo;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;


@RestController
@RequiredArgsConstructor
@RequestMapping("provide/resource")
public class ResourceProvider {

    private final RoleService roleService;
    private final MenuService menuService;
    private final ResourceAPIService resourceAPIService;




    @ApiOperation(value = "查询用户拥有的菜单", notes = "根据用户id查询用户拥有的菜单")
    @GetMapping(value = "/getMenu")
    public Result<List<MenuVo>> getMenu(@RequestParam("userId") String userId) {
        List<MenuVo> pageList = menuService.getMenu(userId);
        return Result.success(pageList);
    }




    @ApiOperation(value = "查询用户拥有的按钮", notes = "根据用户id查询用户拥有的按钮")
    @GetMapping(value = "/getButton")
    public Result<List<MenuVo>> getButton(@RequestParam("userId") String userId) {
        List<MenuVo> pageList = menuService.getButton(userId);
        return Result.success(pageList);
    }



    @ApiOperation(value = "查询用户拥有的资源", notes = "根据用户id查询用户拥有的资源api")
    @GetMapping(value = "/user")
    public Result<List<String>> queryResourceByUser(@RequestParam String userId) {

        List<ResourceAPI> resourceAPIS = resourceAPIService.queryResourceByUserId(userId);
        return Result.success(resourceAPIS.stream().map(ResourceAPI::toVo).toList());
    }





    @ApiOperation(value = "根据用户id查询角色", notes = "根据用户id查询用户所拥有的角色信息")
    @GetMapping(value = "/role")
    public Result<List<RoleVo>> queryByUser(@RequestParam String userId) {
        return Result.success(roleService.queryByUserId(userId));
    }









}
